/**
*====================================================
* 文件名称: MyProtocolDecoder.java
* 修订记录：
* No    日期				作者(操作:具体内容)
* 1.    2010-1-22			李自立(创建:创建文件)
*====================================================
* 类描述：(说明未实现或其它不应生成javadoc的内容)
* 
*/
package com.sunsharing.transport.mina;

import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

import com.sunsharing.common.Context;
import com.sunsharing.common.ContextCreate;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

/**
 *<pre><b><font color="blue">MyProtocolDecoder</font></b></pre>
 *
 *<pre><b>&nbsp;--描述说明--</b></pre>
 * <pre></pre>
 * <pre>
 * <b>--样例--</b>
 *   MyProtocolDecoder obj = new MyProtocolDecoder();
 *   obj.method();
 * </pre>
 * JDK版本：JDK1.5
 * @author  <b>李自立</b> 
 */
public class MyProtocolDecoder extends CumulativeProtocolDecoder {

	private final Charset charset;

	public MyProtocolDecoder(Charset charset) {
		this.charset = charset;
	}
	
	@Override
	protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
		if (!in.prefixedDataAvailable(4)) {
		    return false;
		}
		int length = in.getInt();
        byte[] bytes = new byte[length];
        in.get(bytes);
        //String tmp = new String(bytes,"UTF-8");
		out.write(ContextCreate.createContextByByteArray(bytes));
		return true;

	}

	

}
